home *** CD-ROM | disk | FTP | other *** search
-
- #pragma segment MENUS
-
-
- /*
- ** This source code was written by Tim Endres
- ** Email: time@ice.com.
- ** USMail: 8840 Main Street, Whitmore Lake, MI 48189
- **
- ** Some portions of this application utilize sources
- ** that are copyrighted by ICE Engineering, Inc., and
- ** ICE Engineering retains all rights to those sources.
- **
- ** Neither ICE Engineering, Inc., nor Tim Endres,
- ** warrants this source code for any reason, and neither
- ** party assumes any responsbility for the use of these
- ** sources, libraries, or applications. The user of these
- ** sources and binaries assumes all responsbilities for
- ** any resulting consequences.
- */
-
-
- #include "tickle.h"
- #include "tge.h"
- #include "tclMac.h"
-
- #define MAX_SCRIPT_MENU_ITEMS 32
-
- char *script_menu_commands[MAX_SCRIPT_MENU_ITEMS];
-
-
- create_menus()
- {
- int i;
-
- apple_menu_hdl = NewMenu(applemenu, applemname);
- AppendMenu(apple_menu_hdl, applemstr);
- AddResMenu(apple_menu_hdl, (ResType)'DRVR');
- InsertMenu(apple_menu_hdl, 0);
-
- file_menu_hdl = GetMenu((short) filemenu);
- InsertMenu(file_menu_hdl, 0);
-
- edit_menu_hdl = GetMenu((short) editmenu);
- InsertMenu(edit_menu_hdl, 0);
-
- tcl_menu_hdl = GetMenu((short) tcl_menu);
- InsertMenu(tcl_menu_hdl, 0);
- for ( i = 0 ; i < MAX_SCRIPT_MENU_ITEMS ; ++i )
- script_menu_commands[i] = NULL;
-
- mtool_menu_hdl = GetMenu((short) mtoolmenu);
- InsertMenu(mtool_menu_hdl, 0);
-
- ttool_menu_hdl = GetMenu((short) ttoolmenu);
- InsertMenu(ttool_menu_hdl, 0);
-
- hc_submenu_hdl = GetMenu((short) hcsubmenu);
- InsertMenu(hc_submenu_hdl, hierMenu);
-
- xc_submenu_hdl = GetMenu((short) xcsubmenu);
- InsertMenu(xc_submenu_hdl, hierMenu);
-
- utool_menu_hdl = GetMenu((short) utoolmenu);
- InsertMenu(utool_menu_hdl, 0);
-
- tar_menu_hdl = GetMenu((short) tarmenu);
- InsertMenu(tar_menu_hdl, 0);
-
- ptar_menu_hdl = GetMenu((short) ptarmenu);
- InsertMenu(ptar_menu_hdl, hierMenu);
-
- asd_menu_hdl = GetMenu((short) asdmenu);
- InsertMenu(asd_menu_hdl, 0);
-
- stool_menu_hdl = GetMenu((short) stoolmenu);
- InsertMenu(stool_menu_hdl, 0);
-
- stuffit_available = StuffItAvailable();
- if (! stuffit_available)
- DisableItem(stool_menu_hdl, 0);
-
- DrawMenuBar();
- }
-
- yield_menus(turn_on)
- int turn_on;
- {
- WindowPtr myWindow;
-
- yielding_on = (turn_on == YIELD_ON);
-
- if (turn_on == YIELD_ON)
- {
- EnableItem(file_menu_hdl, (short)cancel_op_item);
- EnableItem(file_menu_hdl, (short)pause_op_item);
-
- DisableItem(file_menu_hdl, (short)new_item);
- DisableItem(file_menu_hdl, (short)open_item);
- DisableItem(file_menu_hdl, (short)save_item);
- DisableItem(file_menu_hdl, (short)save_as_item);
- DisableItem(file_menu_hdl, (short)close_window_item);
- DisableItem(file_menu_hdl, (short)run_script_item);
- DisableItem(file_menu_hdl, (short)quit_item);
-
- /* DisableItem(edit_menu_hdl, (short)0); */
-
- DisableItem(tcl_menu_hdl, (short)0);
-
- DisableItem(mtool_menu_hdl, (short)0);
-
- DisableItem(ttool_menu_hdl, (short)0);
-
- DisableItem(utool_menu_hdl, (short)0);
-
- DisableItem(tar_menu_hdl, (short)0);
-
- DisableItem(stool_menu_hdl, (short)0);
-
- DisableItem(asd_menu_hdl, (short)0);
- }
- else
- {
- DisableItem(file_menu_hdl, (short)cancel_op_item);
- DisableItem(file_menu_hdl, (short)pause_op_item);
-
- EnableItem(file_menu_hdl, (short)run_script_item);
- EnableItem(file_menu_hdl, (short)new_item);
- EnableItem(file_menu_hdl, (short)open_item);
- EnableItem(file_menu_hdl, (short)quit_item);
-
- myWindow = FrontWindow();
- if (myWindow != NULL)
- {
- EnableItem(file_menu_hdl, (short)close_window_item);
- if (WPeek->windowKind == tgeWKind)
- tge_act_menus(myWindow);
- }
-
- /* EnableItem(edit_menu_hdl, (short)0); */
-
- EnableItem(tcl_menu_hdl, (short)0);
-
- EnableItem(mtool_menu_hdl, (short)0);
-
- EnableItem(ttool_menu_hdl, (short)0);
-
- EnableItem(utool_menu_hdl, (short)0);
-
- EnableItem(tar_menu_hdl, (short)0);
-
- if (stuffit_available)
- EnableItem(stool_menu_hdl, (short)0);
-
- EnableItem(asd_menu_hdl, (short)0);
- }
-
- cancel_current_op = 0;
- pause_op = 0;
-
- DrawMenuBar();
- }
-
-
- int
- Cmd_ScriptMenu(clientData, interp, argc, argv)
- char *clientData;
- Tcl_Interp *interp;
- int argc;
- char **argv;
- {
- # pragma unused (clientData, argv)
-
- if (argc < 3)
- {
- Tcl_AppendResult(interp, "wrong # args: should be \"", argv[0], "\"",
- " ADD|DEL item command ?before? ", (char *) NULL);
- return TCL_ERROR;
- }
-
- if (strcmp(argv[1], "ADD") == 0)
- {
- if (argc != 4 && argc != 5)
- {
- Tcl_AppendResult(interp, "wrong # args: should be \"", argv[0], "\"",
- " ADD item command ?before? ", (char *) NULL);
- return TCL_ERROR;
- }
-
- return script_menu_add(interp, argv[2], argv[3], (argc == 5 ? argv[4] : NULL));
- }
- else if (strcmp(argv[1], "DEL") == 0)
- {
- if (argc != 3)
- {
- Tcl_AppendResult(interp, "wrong # args: should be \"", argv[0], "\"",
- " DEL item ", (char *) NULL);
- return TCL_ERROR;
- }
-
- return script_menu_del(interp, argv[2]);
- }
- else
- {
- Tcl_AppendResult(interp, "invalid command \"", argv[1], "\"",
- " must be ADD or DEL ", (char *) NULL);
- return TCL_ERROR;
- }
- }
-
- script_menu_add(interp, item_name, command, before_item)
- Tcl_Interp *interp;
- char *item_name;
- char *command;
- char *before_item;
- {
- int result = TCL_OK;
- int i, numitems, item_num = -1, before_num = -1;
- char itemstr[256];
-
- if (tcl_menu_hdl == NULL)
- {
- Tcl_AppendResult(interp, " scripts menu not found ", (char *) NULL);
- return TCL_ERROR;
- }
-
- if (script_menu_commands[0] == NULL)
- {
- c2pstr(item_name);
- SetItem(tcl_menu_hdl, 1, item_name);
- p2cstr(item_name);
- script_menu_commands[0] = csavestr(command);
- return TCL_OK;
- }
-
- numitems = CountMItems(tcl_menu_hdl);
- for (i=1 ; i <= numitems ; ++i)
- {
- GetItem(tcl_menu_hdl, i, itemstr);
- p2cstr(itemstr);
- if (StrCmp(itemstr, item_name) == 0)
- item_num = i;
- else if (StrCmp(itemstr, before_item) == 0)
- before_num = i;
- }
-
- if (item_num != -1)
- {
- }
- else if (before_num != -1)
- {
- item_num = before_num;
- if (item_num < MAX_SCRIPT_MENU_ITEMS)
- {
- InsMenuItem(tcl_menu_hdl, "\pSCRIPT", item_num-1);
- c2pstr(item_name);
- SetItem(tcl_menu_hdl, item_num, item_name);
- p2cstr(item_name);
- for (i=MAX_SCRIPT_MENU_ITEMS - 1; i >= item_num; --i)
- {
- if (script_menu_commands[i-1] != NULL)
- {
- if (script_menu_commands[i] != NULL)
- free(script_menu_commands[i]);
- script_menu_commands[i] = script_menu_commands[i-1];
- script_menu_commands[i-1] = NULL;
- }
- }
- }
- }
- else
- {
- item_num = numitems + 1;
- if (item_num < MAX_SCRIPT_MENU_ITEMS)
- {
- AppendMenu(tcl_menu_hdl, "\pSCRIPT");
- c2pstr(item_name);
- SetItem(tcl_menu_hdl, item_num, item_name);
- p2cstr(item_name);
- }
- }
-
- if (item_num < MAX_SCRIPT_MENU_ITEMS)
- {
- if (script_menu_commands[item_num-1] != NULL)
- free(script_menu_commands[item_num-1]);
-
- script_menu_commands[item_num-1] = csavestr(command);
- }
-
- return TCL_OK;
- }
-
- script_menu_del(interp, item_name)
- Tcl_Interp *interp;
- char *item_name;
- {
- int result = TCL_OK;
- int i, numitems, item_num = -1, before_num = -1;
- char itemstr[256];
-
- if (tcl_menu_hdl == NULL)
- {
- Tcl_AppendResult(interp, " scripts menu not found ", (char *) NULL);
- return TCL_ERROR;
- }
-
- numitems = CountMItems(tcl_menu_hdl);
- if (numitems == 1)
- {
- if (script_menu_commands[0] != NULL)
- {
- SetItem(tcl_menu_hdl, 1, "\pNo Scripts Installed…");
- free(script_menu_commands[0]);
- script_menu_commands[0] = NULL;
- return TCL_OK;
- }
- else
- {
- Tcl_AppendResult(interp, " no scripts installed ", (char *) NULL);
- return TCL_ERROR;
- }
- }
-
- for (i=1 ; i <= numitems ; ++i)
- {
- GetItem(tcl_menu_hdl, i, itemstr);
- p2cstr(itemstr);
- if (StrCmp(itemstr, item_name) == 0)
- {
- item_num = i;
- break;
- }
- }
-
- if (item_num == -1)
- {
- Tcl_AppendResult(interp, "could not find menu item \"", item_name, "\" ", (char *) NULL);
- return TCL_ERROR;
- }
- else
- {
- DelMenuItem(tcl_menu_hdl, item_num);
- if (script_menu_commands[item_num-1] != NULL)
- free(script_menu_commands[item_num-1]);
-
- for (i=item_num; i<MAX_SCRIPT_MENU_ITEMS - 1; ++i)
- {
- if (script_menu_commands[i] != NULL)
- script_menu_commands[i-1] = script_menu_commands[i];
- else
- break;
- }
-
- if (script_menu_commands[i+1] != NULL)
- free(script_menu_commands[i+1]);
- script_menu_commands[i+1] = NULL;
- }
-
- return TCL_OK;
- }
-
- scripts_menu_run(item)
- int item;
- {
- int result = TCL_OK;
- int tclresult,
- line;
- PFI saveproc;
- Handle saveH,
- stdoutH;
- WindowPtr myWindow = NULL;
- Tcl_Interp *interp = g_interp;
-
- extern int tcl_handle_output();
- extern PFI Tcl_SetPrintProcedure();
-
- if (script_menu_commands[item-1] != NULL)
- {
- stdoutH = NewHandle(0);
- if (! CheckOption())
- {
- myWindow = FrontWindow();
-
- if (myWindow != NULL && WPeek->windowKind == tgeWKind)
- {
- interp = (Tcl_Interp *) TGEWPtr->fobject;
- if (interp == NULL)
- {
- message_alert("Could not get window's interpretter.");
- return TCL_ERROR;
- }
- }
- else
- myWindow = NULL;
- }
-
- if (interp != (Tcl_Interp *)0)
- {
- saveH = tcl_Houtput_sethdl(stdoutH);
- saveproc = Tcl_SetPrintProcedure(tcl_handle_output);
-
- tclresult = Tcl_Eval(g_interp, script_menu_commands[item-1], 0, (char **)0);
-
- Tcl_SetPrintProcedure(saveproc);
- tcl_Houtput_sethdl(saveH);
-
- if ( myWindow != NULL &&
- ( GetHandleSize(stdoutH) > 0 ||
- ( interp->result != NULL && interp->result[0] ) ) )
- {
- SetPort(myWindow);
-
- tge_kill_caret(myWindow);
-
- if (TGEWPtr->sel_start != TGEWPtr->sel_end)
- tge_invert_selection(myWindow);
-
- line = tge_find_pos_line(myWindow, TGEWPtr->sel_end);
- TGEWPtr->sel_start =
- tge_selection_line_append_pos(myWindow, line);
- TGEWPtr->sel_end = TGEWPtr->sel_start;
-
- if (GetHandleSize(stdoutH) > 0)
- tge_paste_handle( myWindow, stdoutH );
-
- if (interp->result != NULL && interp->result[0] != '\0')
- tge_paste_buffer( myWindow, interp->result, strlen(interp->result) );
-
- TGEWPtr->sel_start = TGEWPtr->sel_end -
- ( GetHandleSize(stdoutH) +
- (interp->result != NULL ? strlen(interp->result) : 0) );
-
- SetPort(myWindow);
- tge_compute_selection(myWindow);
- tge_caret_on(myWindow);
- tge_undo_start_typing(myWindow, TGEWPtr->sel_start);
-
- SetPort(myWindow);
- tge_invert_selection(myWindow);
- }
-
- UInitCursor();
-
- result = TCL_OK;
- }
- else
- {
- result = TCL_ERROR;
- }
-
- if (stdoutH != NULL)
- DisposHandle(stdoutH);
-
- return result;
- }
- else
- {
- return TCL_ERROR;
- }
- }
-
-